import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:get/get.dart';
import 'package:flutter_template/provider/index.dart';
import 'package:flutter_template/generated/i18n.dart';
import 'package:flutter_template/routes/index.dart';
import 'package:flutter_template/widget/toast.dart';
import 'package:flutter_template/page/main_page.dart';

//默认App的启动
class DefaultApp {
  //运行app
  static void run() {
    WidgetsFlutterBinding.ensureInitialized();
    SPUtils.init()
        .then((value) => runApp(Store.init(ToastUtils.init(MyApp()))));
    initApp();
  }

  //程序初始化操作
  static void initApp() {
    //XHttp.init();
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Consumer2<AppTheme, LocaleModel>(
      builder: (context, appTheme, localeModel, _) {
        return GetMaterialApp(
          title: 'Flutter Demo',
		  //定义颜色主题
          theme: ThemeData(
            primarySwatch: appTheme.themeColor,
            //buttonColor: appTheme.themeColor,
			//scaffoldBackgroundColor: Color.fromRGBO(237, 237, 237, 1)
		  ),
          getPages: Routes.getPages,
          defaultTransition: Transition.rightToLeft,
		  locale: localeModel.getLocale(),
		  supportedLocales: I18n.delegate.supportedLocales,
          localizationsDelegates: [
            I18n.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
        );
      }
	);
  }
}

